<!doctype html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>添加管理员| 校园知事</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/appadmin.css">
</head>
<body>
     {{template "admin/naver.html" .}}
        <!-- content start -->
        <div class="admin-content">
            <div class="admin-content-body">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg"  style="color: #222222;">添加普通管理员</strong> </div>
                </div>
                <hr />
                <div class="am-g">
                    <div class="am-u-sm-12 am-u-md-8">
                        <form class="am-form am-form-horizontal">
                            <div class="am-form-group">
                                <label for="num" class="am-u-sm-3 am-form-label">账号</label>
                                <div class="am-u-sm-9">
                                    <input type="text" id="num" onblur="checkRepeat()" maxlength="16" placeholder="请输入账号">
                                    <small>必填</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="pwd" class="am-u-sm-3 am-form-label">密码</label>
                                <div class="am-u-sm-9">
                                    <input type="text" maxlength="20" id="pwd" value="123456" placeholder="请输入密码">
                                     <small>必填</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="name" class="am-u-sm-3 am-form-label">管理员姓名</label>
                                <div class="am-u-sm-9">
                                    <input type="tel" id="name" maxlength="20" placeholder="请输入管理员姓名">
                                     <small>必填</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label for="phone" class="am-u-sm-3 am-form-label">手机号码</label>
                                <div class="am-u-sm-9">
                                    <input type="text" id="phone" maxlength="12" placeholder="请输入手机号码">
                                </div>
                            </div>
                             <div class="am-form-group">
                                <label for="email" class="am-u-sm-3 am-form-label">邮箱</label>
                                <div class="am-u-sm-9">
                                    <input type="email" id="email" maxlength="50" placeholder="请输入邮箱">
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3">
                                    <button type="button" class="am-btn am-btn-primary" onclick="addNewUser()">保存添加</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
       {{template "admin/footer.html" .}}
       <script src="/assets/js/jquery.md5.min.js"></script>
	 <script src="/assets/js/appadmin.js"></script>
       <script type="text/javascript">
       	function addNewUser(){
			var $num=$("#num");
			if ($num.val().trim()==='') {
				  layer.tips('请输入账号', $num);
				  $num.focus();
				return ;
			}
			var $pwd=$("#pwd");
			if ($pwd.val().trim()==='') {
			 	layer.tips('请输入密码', $pwd);
			 	$pwd.focus();
				return ;
			}
			if ($pwd.val().trim().length<6) {
			 	layer.tips('密码应大于6位', $pwd);
			 	$pwd.focus();
				return ;
			}
			var $name=$("#name");
			if ($name.val().trim()==='') {
			 	layer.tips('请输入管理员姓名', $name);
			 	$name.focus();
				return ;
			}
			var $phone=$("#phone");
			var $email=$("#email");
			if ($email.val().trim().length>0) {
				if (!checkMail($email.val().trim())) {
					layer.tips('请输入正确的邮箱', $email);
			 		$email.focus();
					return ;
				}
			}
			$.lintul('/admin/user/addnew',{num:$num.val().trim(),pwd:$.md5($pwd.val().trim()),name:$name.val().trim(),phone:$phone.val().trim(),email:$email.val().trim()},function(data){
				 if (data.status === 1) {
                        layer.msg('添加成功', { offset: '15%', icon: 6 }, function () {
                            window.location.href = '/admin/user';
                        });
                    } else {
                        layer.msg('添加失败,请检查后重试', { offset: '15%', icon: 5 });
                    }
			});
       	}
       	function checkRepeat(){
       		var $num=$("#num");
       		if ($num.val().trim()==='') {
				return ;
			}
			$.lintul('/admin/user/repeat',{num:$num.val()},function(data){
				if (data.status===1) {
					 layer.tips('此账号重复', $num);
					 $num.focus();
				}
			});
       	}
       	function checkMail(mail) {
		 var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		 if (filter.test(mail)) return true;
		 return false;
		}
       </script>
</body>
</html>
